#pragma systemFile

const string savedFile = "sensorLog.txt";
#define ENTER "\r\n"
#define seporator " , "

short hFileHandle = 10;
short nFileSize = 40000;

TFileIOResult IoResult;

void sensorLogBegin(string input, string input1, string input2, string input3);
void sensorLog(int input, int input1, int input2, int input3);
void sensorLogEnd();

void sensorLog(int input, int input1, int input2, int input3) {
  string data[5];
  StringFormat(data[0], "%4d", input);
  StringFormat(data[1], "%4d", input1);
  StringFormat(data[2], "%4d", input2);
  StringFormat(data[3], "%4d", input3);
  for (int i = 0; i < 4; i++) {
    strTrim(data[i]);    //get rid of the annoying white spaces
    strcat(data[i], seporator);
    WriteString(hFileHandle, IoResult, data[i]);
  }
  WriteString(hFileHandle, IoResult, ENTER);
}

void sensorLogBegin(string input, string input1, string input2, string input3) {
  OpenWrite(hFileHandle, IoResult, savedFile, nFileSize);
  if (IoResult > 0) {
    Delete(savedFile, IoResult);
    OpenWrite(hFileHandle, IoResult, savedFile, nFileSize);
  }
  strcat(input, input1);
  strcat(input, input2);
  strcat(input, input3);
  WriteString(hFileHandle, IoResult, input);
  WriteString(hFileHandle, IoResult, ENTER);
}


void sensorLogEnd() {
  Close(hFileHandle, IoResult);
}
